<?php
namespace App\Models;

use Illuminate\Database\Eloquent\Model;
use Illuminate\Pagination\LengthAwarePaginator;
use Illuminate\Support\Facades\Request;

//区扩展model
class AreaExtend extends  Model{
    protected $table='area_extend';

    const DB_FIELDS = 'bgsi_ip,port,area,name,login_name,db_password,open_time';

    public function selectdb($select = ''){
        return 'mysql_bgac';
    }

    public function getConnectionName(){
        return $this->selectdb();
    }

    
    public static function assignByOut(&$one, $out){
        $flds = explode(',', self::DB_FIELDS);
        
        foreach ($flds as $fld) {
            $fld = trim($fld);
            isset($out[$fld]) && $one->{$fld} = $out[$fld];
        }

        if (!empty($one->open_time) && (int)$one->open_time !== $one->open_time)
        {
            $one->open_time = strtotime($one->open_time);
        }
    }

    public static function getAreaObj($area){
        $data = \DB::table('area_extend')->where('area', $area)->first();
        return $data;
    }
}